//
//  TIMGrpDetailTableViewCell.m
//  Demo_sdk
//
//  Created by Deli Xia on 2018/7/3.
//  Copyright © 2018年 Deli Xia. All rights reserved.
//

#import "TIMGrpDetailTableViewCell.h"
#import "TIMDemoMacro.h"
#import "Masonry.h"
#import "UIView+Extension.h"

@implementation TIMGrpDetailTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self init_TPSGroupDetailCell];
    }
    return self;
}

- (void)init_TPSGroupDetailCell {
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
    self.selectedBackgroundView.backgroundColor = RGBAColor(238, 238, 238, 1);
    
    self.goImgView = [[UIImageView alloc]initWithImage:kLOADIMAGE(@"mine_edit_go")];
    self.goImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:self.goImgView];
    
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.font = TPSFontSize(14);
    self.titleLab.textColor = RGBColor(51, 51, 51);
    self.titleLab.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.titleLab];
    
    self.detailLab = [[UILabel alloc] init];
    self.detailLab.font = TPSFontSize(14);
    self.detailLab.textColor = RGBColor(153, 153, 153);
    self.detailLab.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.detailLab];
    
    self.QRImgView = [[UIImageView alloc]initWithImage:kLOADIMAGE(@"mineQRCode_image")];
    self.QRImgView.contentMode = UIViewContentModeScaleAspectFit;
    self.QRImgView.hidden = YES;
    [self.contentView addSubview:self.QRImgView];
    
    self.lineView = [[UIView alloc] init];
    self.lineView.backgroundColor = RGBColor(240, 240, 240);
    [self.contentView addSubview:self.lineView];
    
    [self setupConstraints];
}

- (void)setupConstraints {
    
    [self.goImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.trailing.mas_offset(-15);
        make.centerY.mas_equalTo(self.titleLab.centerY);
    }];
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(12);
        make.left.mas_offset(15);
    }];
    
    [self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.goImgView.mas_leading).offset(-5);
        make.centerY.mas_equalTo(self.titleLab.centerY);
        make.width.mas_equalTo(Screen_Width - 160);
    }];
    
    [self.QRImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.goImgView.mas_leading).offset(-5);
        make.centerY.mas_equalTo(self.titleLab.centerY);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.trailing.mas_offset(0);
        make.bottom.mas_offset(0);
        make.height.mas_equalTo(1);
    }];
}

- (void)setIsShowQR:(BOOL)isShowQR {
    _isShowQR = isShowQR;
    self.QRImgView.hidden = !_isShowQR;
    self.detailLab.hidden = _isShowQR;
}

@end

@implementation TIMAnnouncementTableViewCell
- (void)init_TPSGroupDetailCell {
    [super init_TPSGroupDetailCell];
    self.detailLab.hidden = YES;
    
    self.announcementLabel = [[UILabel alloc] init];
    self.announcementLabel.font = TPSFontSize(14);
    self.announcementLabel.numberOfLines = 2;
    self.announcementLabel.textColor = RGBColor(153, 153, 153);
    [self.contentView addSubview:self.announcementLabel];
    
    [self.announcementLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLab.mas_bottom).offset(6);
        make.left.mas_offset(15);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(Screen_Width-45-10);
    }];
}

- (void)fillData:(NSString *)announcementInfo {
    self.announcementLabel.text = announcementInfo;
    [self.announcementLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(38);
    }];
    [self.goImgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
}

@end

@implementation TIMGroupOperationTableViewCell
- (void)init_TPSGroupDetailCell {
    [super init_TPSGroupDetailCell];
    self.isShowQR = NO;
    self.QRImgView.hidden = YES;
    self.goImgView.hidden = YES;
    self.detailLab.hidden = YES;
    
    self.operationSwitch = [[UISwitch alloc] init];
    self.operationSwitch.onTintColor = UIColor.blueColor;
    
    //状态需要储存到数据库。
    //    self.operationSwitch.on = NO;
    [self.operationSwitch addTarget:self action:@selector(operationAction:) forControlEvents:UIControlEventValueChanged];
    [self.contentView addSubview:self.operationSwitch];
    
    [self.operationSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(51, 31));
        make.trailing.mas_offset(-12);
        make.centerY.mas_equalTo(self.titleLab.centerY);
    }];
}

- (void)operationAction:(UISwitch *)sender {
    if (self.operationBlock) {
        self.operationBlock(self.operationSwitch.isOn);
    }
}
@end

@implementation TIMGroupShowMoreTableViewCell
- (void)init_TPSGroupDetailCell {
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = TPSFontSize(14);
    self.titleLabel.textColor = RGBColor(153, 153, 153);
    self.titleLabel.textAlignment = NSTextAlignmentRight;
    self.titleLabel.text = @"查看更多群成员";
    [self.contentView addSubview:self.titleLabel];
    
    self.arrow = [[UIImageView alloc] initWithImage:kLOADIMAGE(@"mine_edit_go")];
    self.arrow.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:self.arrow];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
    }];
    
    [self.arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.and.with.mas_equalTo(20);
        make.leading.equalTo(self.titleLabel.mas_trailing).offset(5);
        make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
    }];
}
@end

#import "TPSGroupUserCell.h"

@implementation TIMGroupUserTableViewCell
- (void)init_TPSGroupDetailCell {
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = RGBColor(243, 243, 243);
    [self.contentView addSubview:bgView];
    
    [self.contentView addSubview:self.userCollectionView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView);
        make.left.and.right.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1);
    }];
    [self.userCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.contentView);
    }];
}

#pragma mark - UICollectionViewDelegate
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return  0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return  25/2;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(45, 75);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(15, 25, 5, 25);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.needConut;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TPSGroupUserCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TPSGroupUserCellID" forIndexPath:indexPath];
    
    if (indexPath.row < self.count) {
        TIMUserInfo *user = self.grpUsers[indexPath.row];
        [cell setUser:user];
    } else {
        NSArray *imgArr = @[@"Group_addUserImg", @"Group_delectUserImg"];
        [cell setUser:nil];
        if (indexPath.row - self.count < 2) {
            cell.avatarImgView.image = [UIImage imageNamed:imgArr[indexPath.row - self.count]];
        }
        cell.userName.text = nil;
    }
    return cell;
}

-(void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    //代理传值
    if([self.UserTableViewCellDelegateColl respondsToSelector:@selector(ClickCooRow:)]) {
        [self.UserTableViewCellDelegateColl ClickCooRow:indexPath.row];
    }
}

- (UICollectionView *)userCollectionView {
    if (!_userCollectionView) {
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _userCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
        _userCollectionView.backgroundColor = [UIColor clearColor];
        _userCollectionView.delegate = self;
        _userCollectionView.dataSource = self;
        _userCollectionView.scrollEnabled = NO;
        _userCollectionView.showsVerticalScrollIndicator = YES;
        _userCollectionView.showsHorizontalScrollIndicator = NO;
        [_userCollectionView registerClass:[TPSGroupUserCell class] forCellWithReuseIdentifier:@"TPSGroupUserCellID"];
    }
    return _userCollectionView;
}
@end
